home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / Nil.c < prev    next >
C/C++ Source or Header  |  1990-05-20  |  5KB  |  177 lines

  1. /* Nil.c -- implementation of the nil object
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     September, 1985
  21.  
  22. Function:
  23.     
  24. Declarations and member functions for the nil object.
  25.  
  26. $Log:    Nil.c,v $
  27.  * Revision 3.0  90/05/20  11:34:10  kgorlen
  28.  * Release for 1st edition.
  29.  * 
  30. */
  31.  
  32. #include "Object.h"
  33.  
  34. class Nil : public VIRTUAL Object {
  35.     DECLARE_MEMBERS(Nil);
  36.     Nil(const Nil&) {}
  37. public:    
  38.     Nil() {}
  39.     virtual int compare(const Object&) const; // compare objects 
  40.     virtual Object* copy() const;        // copy returns nil 
  41.     virtual Object* deepCopy();        // copy returns nil 
  42.     virtual void dumpOn(ostream& strm =cerr) const;
  43.     virtual unsigned hash() const;        // calculate object hash 
  44.     virtual bool isEqual(const Object&) const;    // equality test 
  45.     virtual void printOn(ostream& strm =cout) const;
  46. private:                        // shouldNotImplement 
  47.     virtual void deepenShallowCopy();
  48.     virtual void storer(OIOout&) const;
  49.     virtual    void storer(OIOofd&) const;
  50. };
  51.  
  52. extern const int NIHCL_RDUNKCLASS;
  53.  
  54. Object*    const Object::nil = 0;        // initialized by NIHCL::NIHCL()
  55.  
  56. #define    THIS    Nil
  57. #define    BASE    Object
  58. #define BASE_CLASSES BASE::desc()
  59. #define MEMBER_CLASSES
  60. #define VIRTUAL_BASE_CLASSES Object::desc()
  61.  
  62. Object* Nil::reader(OIOin&)        { setError(NIHCL_RDUNKCLASS,DEFAULT,"Nil"); return nil; }
  63. Object* Nil::reader(OIOifd&)        { setError(NIHCL_RDUNKCLASS,DEFAULT,"Nil"); return nil; }
  64. Object* Nil::shallowCopy() const    { return nil; }
  65.  
  66. _DEFINE_CLASS_ALWAYS(Nil,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Nil.c,v 3.0 90/05/20 11:34:10 kgorlen Rel $",NULL,NULL)
  67. _DEFINE_CASTDOWN(Nil)
  68.  
  69. bool Nil::isEqual(const Object& ob) const { return (&ob==nil); }
  70.  
  71. unsigned Nil::hash() const { return 0; }
  72.  
  73. int Nil::compare(const Object& ob) const
  74. {
  75.     assertArgSpecies(ob,classDesc,"compare");
  76.     return 0;
  77. }
  78.  
  79. Object* Nil::copy() const { return nil; }
  80.  
  81. Object* Nil::deepCopy() { return nil; }
  82.  
  83. void Nil::dumpOn(ostream& strm) const { strm << "NIL"; }
  84.  
  85. void Nil::printOn(ostream& strm) const { strm << "NIL"; }
  86.  
  87. void Nil::deepenShallowCopy()    { shouldNotImplement("deepenShallowCopy"); }
  88.  
  89. Nil::Nil(OIOin&) {}
  90.  
  91. Nil::Nil(OIOifd&) {}
  92.  
  93. void Nil::storer(OIOout&) const
  94. /*
  95. The Nil object is always implicitly stored as object number zero; all
  96. references to nil are stored as @0.
  97. */
  98. {
  99.     shouldNotImplement("storer");
  100. }
  101.  
  102. void Nil::storer(OIOofd&) const
  103. {
  104.     shouldNotImplement("storer");
  105. }
  106.  
  107. //----------------------------------------------------------------------
  108.  
  109. // NIH Class Library Initialization
  110.  
  111. #include <errlib.h>
  112.  
  113. int NIHCL::initCount = 0;
  114. bool NIHCL::init = NO;
  115. unsigned char NIHCL::char_bit_mask[sizeof(char)*8];
  116. unsigned short NIHCL::short_bit_mask[sizeof(short)*8];
  117. unsigned int NIHCL::int_bit_mask[sizeof(int)*8];
  118. unsigned char NIHCL::bit_count[256];
  119. unsigned char NIHCL::bit_reverse[256];
  120.  
  121.  
  122. void NIHCL::initTables()
  123. {
  124.     register unsigned i,j;
  125.     
  126.     for (i=0, j=1; i<sizeof(char)*8; i++, j <<= 1) char_bit_mask[i] = j;
  127.     for (i=0, j=1; i<sizeof(short)*8; i++, j <<= 1) short_bit_mask[i] = j;
  128.     for (i=0, j=1; i<sizeof(int)*8; i++, j <<= 1) int_bit_mask[i] = j;
  129.  
  130.     for (i=0; i<256; i++) {
  131.         bit_count[i] = 0;
  132.         j = i;
  133.         while (j != 0) {
  134.             bit_count[i]++;
  135.             j &= j-1;
  136.         }
  137.     }
  138.     
  139.     for (i=0; i<256; i++) {
  140.         bit_reverse[i] = 0;
  141.         j = i;
  142.         register unsigned char m = 0x80;
  143.         while (j != 0) {
  144.             if ((j&1) != 0) bit_reverse[i] |= m;
  145.             j >>= 1;
  146.             m >>= 1;
  147.         }
  148.     }
  149. }
  150.  
  151. extern void NIHCL__errinit();    // error facility initializer for NIHCL
  152.  
  153. NIHCL::NIHCL()
  154. // Called once for every module that includes Object.h
  155. {
  156.     if (initCount++) return;
  157.     NIHCL__errinit();            // initialize the NIHCL error handler 
  158.     seterropt(ERROR,WARNING,NO,3,NULL);
  159.     initTables();                // initialize NIHCL tables
  160.     Object** nilp = (Object**)&Object::nil;    // create the nil object and
  161.     *nilp = new Nil;            // initialize the pointer to it    
  162. }
  163.  
  164. NIHCL::~NIHCL()
  165. // Called once for every module that includes Object.h
  166. {
  167.     if (--initCount) return;
  168. }
  169.  
  170. void NIHCL::initialize()    // NIHCL initialization, called once from _main 
  171.                 // AFTER execution of all static constructors
  172. {
  173.     if (initialized()) return;
  174.     Class::initialize();    // initialize NIHCL classes
  175.     init = YES;
  176. }
  177.